<?php

namespace app\common\model;

use think\facade\Db;

class CourseQuestionBackground extends Base
{
    /**
     * @param $course_id
     * @param $extend_id
     * @param $content
     * @return int
     */
    public function createOrGet($course_id, $extend_id, $content)
    {
        // 查询条件
        $where = [
            'course_id' => $course_id,
            'extend_id' => $extend_id,
        ];

        // 查询数据
        $backgroundId = $this->where($where)->value('id', 0);
        if ($backgroundId > 0) {
            return $backgroundId;
        }

        // 保存数据
        $time = time();
        $saveData = [
            'course_id' => $course_id,
            'extend_id' => $extend_id,
            'value' => $content,
            'a_time' => $time,
        ];
        return $this->add_data($saveData);
    }
}